﻿
var g_test_txtdds = null;
var show_msgsss = function(){
    if (g_test_txtdds != null){
        for(x in g_test_txtdds){
            g_test_txtdds[x].destroy();
        }
    }
    g_test_txtdds = new Array();
    var i = 0;
    var j = 0;
    for (var x in F5Frame.gameObjects.toArray()) {
        var obj = F5Frame.gameObjects.getk(x);
        if(i*15>550)
        {
            i = 0;
            j++;
        }
        var t = new F5Frame.Text().Create({text:obj._id+" "+obj.zLayer+" "+obj.zOrder, x:150+80*j,y:i*15+20,layer:10 });
        g_test_txtdds.push(t);

        i++;
    }

    F5Frame.sortGameObject()

    var i = 0;
    var j = 0;
    for (var x in F5Frame.gameObjects.toArray()) {
        var obj = F5Frame.gameObjects.getk(x);
        if(i*15>550)
        {
            i = 0;
            j++;
        }
        var t = new F5Frame.Text().Create({text:obj._id+" "+obj.zLayer+" "+obj.zOrder, x:350+80*j,y:i*15+20,layer:10 });
        g_test_txtdds.push(t);

        i++;
    }
}

/* 游戏主UI*/
var GF_GameMain = {
    init: function () {
        /** 按钮*/
        //城市列表
        this.btn_city = new F5Frame.Button().Create(550, 15,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_city.click(GF_GameMain.click_city);
        //野外列表
        this.btn_yewai = new F5Frame.Button().Create(630, 15,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_yewai.click(GF_GameMain.click_yewai);
        //离开场景
        this.btn_Leval = new F5Frame.Button().Create(730, 560,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_Leval.click(GF_GameMain.click_leval);

        //战斗区域-搜索怪物
        this.btn_search_monster = new F5Frame.Button().Create(730, 400,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_search_monster.click(GF_GameMain.click_search_monster);

        //玩家信息面板
        this.btn_myinfo = new F5Frame.Button().Create(50, 45,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_myinfo.click(GF_GameMain.click_myinfo);

        this.btn_mybags = new F5Frame.Button().Create(130, 45,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        this.btn_mybags.click(GF_GameMain.click_mybags);

        this.btn_ddbags = new F5Frame.Button().Create(130, 99,
        [srcObj.Btn0101, srcObj.Btn0102, srcObj.Btn0103, srcObj.Btn0103]);
        //this.btn_ddbags.click(show_msgsss);

        this.hide();
        this.cylist = new Array();
    },
    show: function () {
        //this.nForm.show();
    },
    hide: function () {
        //this.nForm.hide();
    },
    /** 游戏UI回调事件
    */
    click_city: function () {
        ajaxMsg(MsgEvent.Citie, null);
    },
    click_yewai: function () {
        ajaxMsg(MsgEvent.Wild, null);
    },
    click_leval: function () {
        //ajaxMsg(MsgEvent.LevalScene, null);
        //离开场景,返回大地图界面
        GF_SceneMgr.update({ CID: 0, CT: SceneEnum.Maps, N: "大地图" });
    },
    click_search_monster: function () {
        ajaxMsg(MsgEvent.Search_Monster, null);
    },
    click_myinfo: function () {
        //获取人物信息
        ajaxMsg(MsgEvent.PInfo, null);

        GF_PlayerInfo.show();
    },
    click_mybags: function () {
        ajaxMsg(MsgEvent.GetItems, null);
    }
}


/* 玩家信息窗口
*/
var GF_PlayerInfo = {
    init: function () {
        this.nForm = null;

        this.txt_Nickname = null;
        this.txt_Level = null;
        this.txt_Race = null;
        this.txt_STR = null;
        this.txt_CON = null;
        this.txt_DEX = null;
        this.txt_INT = null;
        this.txt_WIS = null;
        this.txt_CHA = null;
        this.txt_HP = null;
        this.txt_MP = null;
        this.txt_ATK = null;
        this.txt_DEF = null;
        this.txt_Exp = null;

        this.info = null;

        this.nForm = new F5Frame.Form().Create({ x: 10, y: 100, file: srcObj.FormBgSrc });
        x = 0;
        bpx = 40
        bpy = 15;
        inv = 20;

        bpx_t = 35;

        var txt = new F5Frame.Text().Create({ text: "昵称:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_Nickname = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff", fsize: "14pt" });
        txt = new F5Frame.Text().Create({ text: "种族:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_Race = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "等级:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_Level = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "生命:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_HP = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "魔法:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_MP = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "攻击:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_ATK = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "防御:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_DEF = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "经验:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_Exp = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });

        x = 1;
        bpx_t = 120;
        bpx = bpx_t + 5;
        txt = new F5Frame.Text().Create({ text: "力量:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_STR = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "体质:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_CON = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "敏捷:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_DEX = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "智力:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_INT = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "感知:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_WIS = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });
        txt = new F5Frame.Text().Create({ text: "魅力:", x: bpx_t, y: bpy + (x * inv), align: "right", color: "#ffffff" });
        this.nForm.appendChild(txt);
        this.txt_CHA = new F5Frame.Text().Create({ x: bpx, y: bpy + (x++ * inv), align: "left", color: "#ffffff" });

        this.nForm.appendChild(this.txt_Nickname);
        this.nForm.appendChild(this.txt_Level);
        this.nForm.appendChild(this.txt_Race);
        this.nForm.appendChild(this.txt_STR);
        this.nForm.appendChild(this.txt_CON);
        this.nForm.appendChild(this.txt_DEX);
        this.nForm.appendChild(this.txt_INT);
        this.nForm.appendChild(this.txt_WIS);
        this.nForm.appendChild(this.txt_CHA);
        this.nForm.appendChild(this.txt_HP);
        this.nForm.appendChild(this.txt_MP);
        this.nForm.appendChild(this.txt_ATK);
        this.nForm.appendChild(this.txt_DEF);
        this.nForm.appendChild(this.txt_Exp);
        this.nForm.hide();
    },

    show: function () {
        this.nForm.show();
    },

    update: function (obj) {
        this.info = obj;
        this.txt_Level.setText(obj.Level);
        this.txt_Race.setText(obj.Race);
        this.txt_STR.setText(obj.STR);
        this.txt_CON.setText(obj.CON);
        this.txt_DEX.setText(obj.DEX);
        this.txt_INT.setText(obj.INT);
        this.txt_WIS.setText(obj.WIS);
        this.txt_CHA.setText(obj.CHA);
        this.txt_HP.setText(obj.HP);
        this.txt_MP.setText(obj.MP);
        this.txt_ATK.setText(obj.AS + " - " + obj.AM);
        this.txt_DEF.setText(obj.DS + " - " + obj.DM);
        this.txt_Exp.setText(obj.EX);
    }
}

/*城市列表*/
var GF_City = {
    init: function () {
        this.nForm = new F5Frame.Form().Create({ x: 575, y: 35, file: srcObj.FormBgSrc });
        this.hide();
        this.cylist = new Array();
    },
    show: function () {
        this.nForm.show();
    },
    hide: function () {
        this.nForm.hide();
    },
    update: function (clist) {
        for (x in this.cylist) {
            this.cylist[x].destroy();
        }
        this.cylist.splice(0, this.cylist.length);

        for (x in clist) {
            obj = clist[x];
            //创建一个文字绑定在窗口上
            t = new F5Frame.Text().Create({ text: obj.Name, x: 5, y: 10 + (x * 20), align: "left", color: "#ffffff" });
            t.click(GF_City.clickCity, { arg1: obj.ID, arg2: obj.Name });
            this.nForm.appendChild(t);
            this.cylist.push(t);
        }
    },
    clickCity: function (id, name) {
        ajaxMsg(MsgEvent.GotoPlace, id);
    }
}
/*野外列表*/
var GF_Wild = {
    init: function () {
        this.nForm = new F5Frame.Form().Create({ x: 575, y: 210, file: srcObj.FormBgSrc });
        this.hide();
        this.cylist = new Array();
    },
    show: function () {
        this.nForm.show();
    },
    hide: function () {
        this.nForm.hide();
    },
    update: function (clist) {
        for (x in this.cylist) {
            this.cylist[x].destroy();
        }
        this.cylist.splice(0, this.cylist.length);

        for (x in clist) {
            obj = clist[x];
            //创建一个文字绑定在窗口上
            t = new F5Frame.Text().Create({ text: obj.Name, x: 5, y: 10 + (x * 20), align: "left", color: "#ffffff" });
            t.click(GF_Wild.clickCity, { arg1: obj.ID, arg2: obj.Name });
            this.nForm.appendChild(t);
            this.cylist.push(t);
        }
    },
    clickCity: function (id, name) {
        ajaxMsg(MsgEvent.GotoPlace, id);
    }
}

/*背包*/
var GF_Bags = {
    init: function () {
        this.nForm = new F5Frame.Form().Create({ x: 250, y: 100, file: srcObj.BagBg });
        this.hide();
        this.cylist = new Array();
        var tglod = new F5Frame.Text().Create({ text: "通用币", x: this.nForm.getWidth()*0.7, y: this.nForm.getHeight()*0.8, align: "right", color: "#efef11" });
        this.txt_glod = new F5Frame.Text().Create({ x: this.nForm.getWidth()*0.8, y: this.nForm.getHeight()*0.8, align: "right", color: "#eeff11" });
        this.nForm.appendChild(this.txt_glod);
        this.nForm.appendChild(tglod);
    },
    show: function () {
        this.nForm.show();
    },
    hide: function () {
        this.nForm.hide();
    },
    update: function (obj) {
        var clist = obj.data;
        var glod = obj.Gold;
        for (x in this.cylist) {
            this.cylist[x].destroy();
        }
        this.cylist.splice(0, this.cylist.length);

        for (x in clist) {
            obj = clist[x];
            //创建一个文字绑定在窗口上
            t = new F5Frame.Text().Create({ text: obj.n, x: 60, y: 30 + (x * 20), align: "right", color: "#0044fe" });
            t.drag(true);
            t.click_right(this.rclick_Items, {arg1:obj.i, arg2:obj.n, arg3:obj.g});
            this.nForm.appendChild(t);
            this.cylist.push(t);
        }
        if(GF_PlayerInfo.info != null){
            this.txt_glod.setText(glod);
        }
    },
    rclick_Items: function (id, name, gold) {
        GF_ShopItems.click_shopItemSell(id, name, gold);
    }
}

/*商品信息列表*/
var GF_ShopItems = {
    init: function () {
        this.nForm = new F5Frame.Form().Create({ x: 20, y: 300, file: srcObj.ShopItemsBg });
        this.hide();
        this.cylist = new Array();

        this.msgdialog = null;
    },
    show: function () {
        this.nForm.show();
    },
    hide: function () {
        this.nForm.hide();
    },
    update: function (obj) {
        for (x in this.cylist) {
            this.cylist[x].destroy();
        }
        this.cylist.splice(0, this.cylist.length);

        var t = new F5Frame.Text().Create({ text: obj.N, x: 10, y: 10, align: "left", color: "#0044fe" });
        this.nForm.appendChild(t);
        this.cylist.push(t);

        var t = new F5Frame.Text().Create({ text: obj.T, x: 20, y: 25, align: "left", color: "#0044fe" });
        this.nForm.appendChild(t);
        this.cylist.push(t);
        var clist = obj.I;
        for (x in clist) {
            obj = clist[x];
            //名称
            t = new F5Frame.Text().Create({ text: obj.N, x: 60, y: 40 + (x * 20), align: "right", color: "#0044fe" });
            t.click(this.click_shopItem, { arg1: obj.I, arg2: obj.N });
            //价格
            var t2 = new F5Frame.Text().Create({ text: obj.G, x: 65, y: 40 + (x * 20), align: "left", color: "#00eefe" });

            this.nForm.appendChild(t);
            this.nForm.appendChild(t2);
            this.cylist.push(t);
            this.cylist.push(t2);
        }

        this.show();
    },
    click_shopItem: function (id, name) {
        if (GF_ShopItems.msgdialog != null) {
            GF_ShopItems.msgdialog.destroy();
        }
        GF_ShopItems.msgdialog = new F5Frame.MsgDialog().Create({ msg: "是否购买 " + name, x: 280, y: 150, file: srcObj.ShopItemsBg,
            func_ok: GF_ShopItems.shopOk, func_ok_arg1: id, func_cancel: GF_ShopItems.hide_msgdialog });
    },
    click_shopItemSell: function(id, name ,gold){
        if (GF_ShopItems.msgdialog != null) {
            GF_ShopItems.msgdialog.destroy();
        }
        GF_ShopItems.msgdialog = new F5Frame.MsgDialog().Create({ msg: "是否以 "+ gold +" 的价格出售 " + name, x: 280, y: 150, file: srcObj.ShopItemsBg,
            func_ok: GF_ShopItems.shopSellOk, func_ok_arg1: id, func_cancel: GF_ShopItems.hide_msgdialog });
    },
    hide_msgdialog:function(){
        if (GF_ShopItems.msgdialog != null) {
            GF_ShopItems.msgdialog.hide();
        }
    },
    shopOk: function (id) {
        //alert("确认购买" + id);
        ajaxMsg(MsgEvent.ShopBuyItem, id);
    },
    shopSellOk: function (id) {
        ajaxMsg(MsgEvent.ShopSellItem, id);
    },
}
